<template>
	<view class="page">
		<view class="bgBox">
			<div class="bgRed"></div>
			<view class="main">
				<view class="headBox">
					<image class="headPic" v-if="!mood"
						src="https://maofengshuzinongye.oss-cn-chengdu.aliyuncs.com/%E5%89%8D%E7%AB%AF%E5%9B%BE%E7%89%87/ebe9f2ce1b002c30ca569cfaeeed48a.png"
						mode="aspectFill"></image>
					<image class="headPic" v-else :src="mood.avatar" mode="aspectFill"></image>
					<view class="name" v-if="!mood" @click="godenglu">
						去登陆
					</view>
					<view class="name" v-else>
						{{mood.nickName}}
					</view>
				</view>
				<view class="cardBoxPosition">
					<view class="cardBox">
						<image class="bgYellow"
							src="https://maofengshuzinongye.oss-cn-chengdu.aliyuncs.com/%E5%89%8D%E7%AB%AF%E5%9B%BE%E7%89%87/81104d56088e392d067980a25a7d2ae.png"
							mode="aspectFill"></image>
						<view class="cardItem">
							<image class="vipIcon" src="../../static/my/vip.png" mode="aspectFill"></image>
							<view class="title">
								冒丰数字
							</view>
							<view class="btnBox" style="display: flex;align-items: center;" @click="toMyqian">
								<view class="Text1">
									钱包
								</view>
								<u-icon name="arrow-right" color='#8D560D' size="20"></u-icon>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 我的订单 -->
		<view class="listBg">
			<!-- 我的订单 -->
			<view class="listCard">
				<view class="itemHeader">
					<view class="myOrder">
						我的订单
					</view>
					<view class="BtnAll" @click="goOrder()">
						<view class="BtnText">
							查看全部
						</view>
						<image class="right2" src="@/static/my/right2.png" mode="aspectFit"></image>
					</view>
				</view>
				<view class="listBtn">
					<view class="ItemBtn" v-for="(item,i) in list1" :key="i" @click="goDetail(item)">
						<image class="BtnIcon" :src="'../../static/my/'+item.img" mode="aspectFit"></image>
						<view class="name">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>

			<view class="listCard" style="padding-top: 11rpx;">
				<view class="listBtn">
					<view class="ItemBtn" v-for="(item,i) in list2" :key="i" @click="goDetail(item)">
						<image class="BtnIcon" :src="'../../static/my/'+item.img" mode="aspectFit"></image>
						<view class="name">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>
<script>
	import Header from '@/components/header/header.vue'
	export default {
		components: {
			Header
		},
		data() {
			return {
				list1: [{
					img: 'daifukuang.png',
					name: '待付款'
				}, {
					img: 'daifahuo.png',
					name: '待发货'
				}, {
					img: 'daishouhuo.png',
					name: '待收货'
				}, {
					img: 'finshed.png',
					name: '已完成'
				}],


				list2: [{
						img: 'postion.png',
						name: '地址'
					}, {
						img: 'mifeng.png',
						name: uni.getStorageSync('titleKey')
					}, {
						img: 'wendan.png',
						name: '问答'
					}, {
						img: 'erji.png',
						name: '客服'
					}, {
						img: 'kaquan.png',
						name: '礼品卡'
					}, {
						img: 'zhuanzeng.png',
						name: '转赠'
					},
					
					// {
					// 	img: 'team.png',
					// 	name: '团队'
					// },
					
					// {
					// 	img: 'sellIcon.png',
					// 	name: '子蜂箱'
					// }, 
					
					
					{
						img: 'guanyu.png',
						name: '关于' + uni.getStorageSync('titleKey')
					},
					{
						img: 'binnd.png',
						name: '养殖户'
					},
					// {
					// 	img: 'xiaoshou.png',
					// 	name: '代理商'
					// },
					{
						img: 'set.png',
						name: '设置'
					},
				],
				mood: null,
				isfarmer: false
			}
		},
		created() {
			if (uni.getStorageSync('token')) {
				this.cread()
			}
		},
		methods: {
			toMyqian() {
				uni.navigateTo({
					url: '/subPackages/myqian/myqian'
				})
			},
			godenglu() {
				uni.navigateTo({
					url: '/pages/my/login/login'
				})
			},
			async cread() {
				let res = await this.$api.request('system/user/getInfo', 'get', {})
				this.mood = res.data.user
				this.isfarmer = res.data.isfarmer
				this.isAgent = res.data.isAgent
				uni.setStorageSync('userId', res.data.user.id)
			},
			goOrder() {
				uni.navigateTo({
					url: '/pages/my/order/order'
				})
			},
			async daibi() {
				let res = await this.$api.request('farmer/app/topUpRecord/balance')
				if(res.data.code==601){
					uni.showToast({
						title: '正在审核',
						icon: 'none'
					})
					return
				}
			},
			async goDetail(item) {
				if (!uni.getStorageSync('token')) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/my/login/login'
						})
					}, 1000)
				} else {
					switch (item.name) {

						case '待付款':
							uni.navigateTo({
								url: '/pages/my/order/order?status=0'
							})
							break;
						case '待发货':
							uni.navigateTo({
								url: '/pages/my/order/order?status=3'
							})
							break;
						case '待收货':
							uni.navigateTo({
								url: '/pages/my/order/order?status=4'
							})
							break;
						case '已完成':
							uni.navigateTo({
								url: '/pages/my/order/order?status=5'
							})
							break;
						case '地址':
							uni.navigateTo({
								url: '/pages/my/serve/address'
							})
							break;
						case '认养':
							uni.navigateTo({
								url: '/pages/my/adopt/adoptList'
							})

							break;
						case '问答':
							uni.navigateTo({
								url: '/pages/my/serve/question'
							})
							break;
						case '客服':
							wx.makePhoneCall({
								phoneNumber: '13228694956'
							})
							break;
						case '设置':
							uni.navigateTo({
								url: '/pages/my/info/personalInfo'
							})
							break;
						case '礼品卡':
							uni.navigateTo({
								url: '/pages/card/card'
							})
							break;
						case '转赠':
							uni.navigateTo({
								url: '/pages/givePresent/givePresent'
							})
							break;
						case '子蜂箱':
							uni.navigateTo({
								url: '/subPackages/sunbinnd/sunbinnd'
							})
							break;
						case '养殖户':
							uni.navigateTo({
								url: '/subPackages/site/site'
							})
							break;
							case '团队':
								uni.navigateTo({
									url: '/subPackages/team/team'
								})
								break;
						case '代理商':
						if(this.isAgent){
							uni.navigateTo({
								url: '/subPackages/agent/agent'
							})
						}else{
							this.daibi()
							uni.navigateTo({
								url: '/subPackages/addagent/addagent'
							})
						}
							break;
						case '关于认养':
							uni.navigateTo({
								url: '/pages/my/adoptionRules/adoptionRules'
							})
							break;
					}
				}

			}

		}
	}
</script>
<style lang="scss" scoped>
	.page {
		height: calc(100vh - 97rpx);
		background-color: #f6f6f6;
	}

	.listBg {
		padding: 29rpx 20rpx 200rpx;
		box-sizing: border-box;
		background-color: #f6f6f6;
	}

	.listCard {
		width: 710rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 7rpx 8rpx 0rpx rgba(153, 153, 153, 0.3);
		border-radius: 10rpx;
		margin-bottom: 43rpx;

		&:last-child {
			margin-bottom: 0;
		}

		.itemHeader {
			box-sizing: border-box;
			padding: 33rpx 25rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.myOrder {
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;

			}

			.BtnAll {
				display: flex;
				align-items: center;

				.btnText {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #333333;

				}

				.right2 {
					width: 24rpx;
					height: 24rpx;
					margin-left: 16rpx;
				}
			}
		}

		.listBtn {
			display: flex;
			padding: 0 30rpx 37rpx;
			box-sizing: border-box;
			flex-wrap: wrap;


			.ItemBtn {
				display: flex;
				width: calc(100% / 4);
				padding-top: 27rpx;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.BtnIcon {
					width: 60rpx;
					height: 54rpx;
				}

				.name {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #333333;
					margin-top: 30rpx;
				}
			}

		}
	}

	.bgBox {
		width: 750rpx;
		height: 498rpx;
		position: relative;


		.bgRed {
			position: absolute;
			width: 750rpx;
			height: 498rpx;
			background-image: linear-gradient(to right, rgba(254, 71, 30, 1), rgba(212, 1, 1, 1));
		}

		.main {
			width: 750rpx;
			height: 498rpx;
			position: absolute;
			padding-top: 192rpx;
			box-sizing: border-box;

			.headBox {
				padding-left: 44rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;

				.headPic {
					width: 129rpx;
					height: 129rpx;
					border-radius: 50%;
				}

				.name {
					font-size: 34rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					margin-left: 37rpx;
				}
			}

			.cardBoxPosition {
				position: absolute;
				bottom: 0;
				left: 20rpx;
				width: 710rpx;
				height: 147rpx;
			}

			.cardBox {
				position: relative;
				width: 710rpx;
				height: 147rpx;

				.bgYellow {
					position: absolute;
					width: 710rpx;
					height: 147rpx;


				}

				.cardItem {
					position: absolute;
					display: flex;
					align-items: center;
					width: 710rpx;
					height: 147rpx;
					padding: 0 27rpx 0 43rpx;
					box-sizing: border-box;

					.vipIcon {
						width: 79rpx;
						height: 90rpx;
						margin-right: 31rpx;
					}

					.title {
						font-size: 32rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #8D560D;

					}

					.btnBox {
						margin-left: auto;
						display: flex;
						align-items: center;

						.Text1 {
							font-size: 24rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #8D560D;

							margin-right: 16rpx;
						}

						.rightIcon {
							width: 10rpx;
							height: 19rpx;
						}
					}

				}
			}
		}

	}
</style>